import pandas as pd
import numpy as np
import random
from matplotlib import pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import Lasso
from sklearn.ensemble import RandomForestRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.neighbors import KNeighborsRegressor
import numpy as np

df = pd.read_csv(r'E:\house.csv', encoding='gbk')

plt.figure(figsize=(10,8))
my_order = df.groupby(by=["朝向"])["总价"].median().sort_values(ascending=False).index
sns.boxplot(x='朝向',y='总价',data=df,width=0.5,notch=True,order=my_order)

plt.figure(figsize=(10,8))
my_order = df.groupby(by=["装修"])["总价"].median().sort_values(ascending=False).index
sns.boxplot(x='装修',y='总价',data=df,width=0.4,notch=True,order=my_order)

plt.figure(figsize=(10,8))
my_order = df.groupby(by=["产权性质"])["总价"].median().sort_values(ascending=False).index
sns.boxplot(x='产权性质',y='总价',data=df,width=0.2,order=my_order)

plt.figure(figsize=(10,8))
my_order = df.groupby(by=["住宅类别"])["总价"].median().sort_values(ascending=False).index
sns.boxplot(x='住宅类别',y='总价',data=df,width=0.2,order=my_order)

plt.figure(figsize=(10,8))
my_order = df.groupby(by=["建筑结构"])["总价"].median().sort_values(ascending=False).index
sns.boxplot(x='建筑结构',y='总价',data=df,width=0.2,order=my_order)

plt.figure(figsize=(10,8))
my_order = df.groupby(by=["建筑类别"])["总价"].median().sort_values(ascending=False).index
sns.boxplot(x='建筑类别',y='总价',data=df,width=0.2,order=my_order)

plt.figure(figsize=(15,15))
my_order = df.groupby(by=["户型"])["总价"].median().sort_values().index
sns.boxplot(y='户型',x='总价',data=df,width=0.2,order=my_order)

plt.figure(figsize=(15,15))

order = df['户型'].value_counts(ascending=False).index
sns.countplot(y=df['户型'],order=order)